<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
//for stock

echo '<pre>';

function group_assoc($array, $key) {
    $return = array();
    foreach($array as $v) {
        $return[$v[$key]][] = $v;
    }
    return $return;
}

function toArray($obj)
{
    if (is_object($obj)) $obj = (array)$obj;
    if (is_array($obj)) {
        $new = array();
        foreach ($obj as $key => $val) {
            $new[$key] = toArray($val);
        }
    } else {
        $new = $obj;
    }
    return $new;
}

	$myarticles = file_get_contents('cache.txt');
	$objInfo = unserialize($myarticles);
	$arrInfo = toArray($objInfo);	
	//Group the requests by their account_id
	
	//get data group by SupplierName
	$new_list = group_assoc($arrInfo, 'Supplier');
	$manufacturer = array();
	foreach($new_list as $key => $value){
		$manufacturer_id = $key;
		$manufacturer_name = $value[0]['SupplierName'];
		$manufacturer[$key]=$manufacturer_name;
	}
	
	//var_dump($manufacturer);
	
	foreach($manufacturer as $key=>$value){
		
		$q = "INSERT INTO manufacturer (`manufacturer_id`, `name`) value ($key, '$value')";
		
	}
	
	/*
	//get data group by Kparam1
	$new_list = group_assoc($arrInfo, 'Kparam1');
	
	foreach($new_list as $key=>$value){
		$sku = $key;
		foreach($value as $k=>$product){
			$KatalogNumber 	= $value["KatalogNumber"];
			$EdbNumber		= $value["EdbNumber"];
			$SupplierName 	= $value["SupplierName"];
			$ItemGroupName	= $value["ItemGroupName"];
			$Supplier 		= $value["Supplier"];
			$ItemGroup		= $value["ItemGroup"];
			$Ean 			= $value["Ean"];
			$Kparam1		= $value["Kparam1"];
			$Kparam2 		= $value["Kparam2"];
			$Kparam3		= $value["Kparam3"];
			$Kparam4 		= $value["Kparam4"];
			$Kparam5		= $value["Kparam5"];
			$Vparam1 		= $value["Vparam1"];
			$Vparam2		= $value["Vparam2"];
			$Vparam3 		= $value["Vparam3"];
			$Vparam4		= $value["Vparam4"];
			$Vparam5 		= $value["Vparam5"];
			$Qty			= $value["Qty"];
			
		}
	}
	
	*/
	//var_dump($new_list);
	echo '</pre>';


?>
</body>
</html>